import { Extension } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import Collaboration from '@tiptap/extension-collaboration';
import CollaborationCursor from '@tiptap/extension-collaboration-cursor';
import { extensions } from './extensions';
import { CustomFontSize } from './bjqkzpz';
import TextStyle from '@tiptap/extension-text-style';
import { names, colors } from './cldy'

export const useEditorConfig = (ydoc: any, provider: any) => {
    const editorConfig = {
        enableContentCheck: true,
        extensions: [
            StarterKit.configure({
                history: false,  // 禁用内置历史记录，使用协作历史记录
                heading: {
                    levels: [1, 2, 3, 4],
                    HTMLAttributes: {
                        class: 'editor-heading',
                    },
                },
            }),
            TextStyle.configure(),
            ...extensions,
            CustomFontSize,
            // 只保留一个协作配置
            Collaboration.configure({
                document: ydoc,
            }),
            // 只保留一个光标配置
            CollaborationCursor.configure({
                provider: provider,
                user: provider?.awareness?.getLocalState()?.user || {
                    name: names[Math.floor(Math.random() * names.length)],
                    color: colors[Math.floor(Math.random() * colors.length)]
                },
            }),
        ],
        editorProps: {
            attributes: {
                class: 'editor-content',
            },
        },
    };

    return editorConfig;
};